/*
 * @Author: your name
 * @Date: 2022-03-23 10:41:21
 * @LastEditTime: 2022-11-15 14:01:46
 * @LastEditors: YNT 2501512800@qq.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \22-03-19 智慧社区\pages\index\components\user\index.js
 */
import globalModel from '../../../../api/global'
Component({
  options: {
    styleIsolation: 'shared',
  },
  data: {
    userInfo: {},
    isLogin: false,
    cellList: [
      {
        title: '我的订单',
        icon: '/assets/images/user/icon0.png',
        url: '/pages/myOrder/index',
      },
      {
        title: '我的积分',
        icon: '/assets/images/user/icon1.png',
        url: '/subPackages/scorePackages/pages/shoppingMall/index/index',
      },
      // {
      //   title: '我的互动',
      //   icon: '/assets/images/user/icon2.png',
      //   url: '',
      // },
      {
        title: '实名信息',
        icon: '/assets/images/user/icon3.png',
        url: '/subPackages/otherPackages/pages/realnameregistration/index?type=1',
      },
      {
        title: '人脸信息',
        icon: '/assets/images/user/icon2.png',
        url: '/subPackages/otherPackages/pages/face/index',
      },
      {
        title: '车辆信息',
        icon: '/assets/images/user/icon0.png',
        url: '/subPackages/otherPackages/pages/drive/index',
      },
    ],
  },
  observers: {
    userInfo(userInfo) {
      let { avatar_url, nick_name, phone } = userInfo || {}
      let isLogin = Boolean(avatar_url && nick_name)
      this.setData({ isLogin })
    },
  },
  lifetimes: {
    attached: function () {
      globalModel.getUserinfo().then(({ data }) => {
        data.phone = data.phone.replace(/^(\d{3})\d{4}(\d+)/, '$1****$2')
        this.setData({
          userInfo: data,
        })
      })
    },
  },
  methods: {
    checkCell: function (e) {
      let status = this.data.userInfo.status
      if (status == '2') {
        wx.navigateTo({
          url: e.target.dataset.url,
        })
      } else {
        this.triggerEvent('tips', status)
      }
    },
    changeAvator: function () {
      wx.navigateTo({
        url: '/subPackages/otherPackages/pages/avatorImg/index',
      })
    },
  },
})
